<?php
require_once("./common.php");

$poll_id = $_GET['poll_id'];
$name = $_POST['name'];
$other = urlencode($_POST['other']);
$value = 0;

foreach ($_POST['choice'] as $choice){
  $value += $choice;
}

$query = sprintf("INSERT INTO results (poll_id, name, choice, other) VALUES ('%s' , '%s', '%s', '%s');",
         mysql_real_escape_string($poll_id),
         mysql_real_escape_string($name),
         mysql_real_escape_string($value),
         mysql_real_escape_string($other)
         );

mysql_query($query);  

header("Location: poll.php?poll_id=" .  $_GET['poll_id']);
?>
